package com.lg.startertemplate.controller.callc;

import com.lg.startertemplate.utiles.CommandUtils;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "调用系统命令 数据库的导入和导出")
public class CommandController {

    @GetMapping("importData")
    public Boolean importData(String database,String importDir){
//        pg_restore -h 192.168.120.85 -p 5431 -U postgres -d 4_db -v /root/lg/pue/data11
        String[] envp = {"PGPASSWORD=postgres"};
        String comStr = "pg_restore -h 192.168.120.85 -p 5431 -U postgres -d "+database+" -v " + importDir;
        if (CommandUtils.executeLinuxCmd(comStr,envp)==0)
            return true;

        return false;
    }


    @GetMapping("exportData")
    public Boolean exportData(String exportDir){
//  java -jar placeservice-6.1.0-snapshot.jar "pg_dump -h 192.168.120.85 -p 5431 -U postgres -d place0922_base -F d -f ./test6" "PGPASSWORD=postgres"

        String[] envp = {"PGPASSWORD=postgres"};
        String comStr = "pg_dump -h 192.168.120.85 -p 5431 -U postgres -d place0922_base -F d -f ./" + exportDir;
        if (CommandUtils.executeLinuxCmd(comStr,envp)==0)
            return true;

        return false;

    }
}
